package com.liyunc.demo.bundle.file.manager.config;

import lombok.Data;
import lombok.ToString;
import org.apache.commons.lang3.SystemUtils;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.nio.file.Paths;
import java.util.Objects;

@ConfigurationProperties(prefix = "demo.asset-file")
@Data
@ToString
public class AssetFileConfigProperties {
    private Long defaultLimitSize;
    private String storageRoot;
    private String storageRule;

    private static final Long SIZE = 1024L * 1024L * 10;
    private static final String ROOT = SystemUtils.getUserDir().toString();
    private static final String RULE = "time";

    @PostConstruct
    private void init() {
        if (Objects.isNull(defaultLimitSize)) {
            defaultLimitSize = SIZE;
        }
        if (Objects.isNull(storageRoot)) {
            storageRoot = Paths.get(ROOT, "asset_file_storage").toString();
        }
        if (Objects.isNull(storageRule)) {
            storageRule = RULE;
        }
    }
}
